﻿
@{
    Layout = "";
}
<div ng-controller="MyFavoriteCtrl">
    <div class="flayout_n_main" ng-show="reddit.items.length==0">
        <img src="/Content/images/empty_car.jpg" alt="为空" class="flayout_n_img">
        <p class="flayout_n_emptyTxt">您还没有收藏</p>
        <p class="flayout_n_tobuy">赶紧去商城逛逛吧！</p>
        <a ui-sref="shop.index" class="flayout_n_tobuyBtn">返回首页</a>
    </div>
    <div class="flayout_g_main" ng-show="reddit.items.length>0" infinite-scroll='reddit.nextPage()' infinite-scroll-disabled='reddit.busy' infinite-scroll-distance='0'>
        <div class="flayout_g_eachTimeSlot">

            <div class="flayout_g_proBox"  ng-repeat="favorite in reddit.items">
                <div class="flayout_g_proImg"><img ng-src="{{ImgHostUrl+favorite.ProductImgUrl}}"></div>
                <div class="flayout_g_proInfo">
                    <p class="flayout_g_proName" ui-sref="shop.productdetail({sku:favorite.ProductSku,activityId:0})">{{favorite.ProductName}}</p>

                    <div class="flayout_g_proPrice" style="margin-top: 35px;">
                        <span class="span1">¥</span><span class="span2">{{favorite.Price}}</span><label class="label">¥{{favorite.MarketPrice}}</label>
                    </div>
                    <a href="javascript:void(0)" class="flayout_g_abtn" style="font-size: 12px;margin-bottom: 5px" ng-click="CancelFavorite($index,favorite)">取消收藏</a>
                </div>
            </div>

        </div>
    </div>
</div>
<script type="text/javascript">
    App.controller('MyFavoriteCtrl', [
            '$scope', '$http', '$rootScope', 'Reddit', '$stateParams', '$state',
        function ($scope, $http, $rootScope,Reddit, $stateParams, $state) {
            
            $scope.reddit = new Reddit("/Product/GetMyFavorite", { Take: 5 }, function (response) { });
            console.log($scope.reddit);
            //$scope.reddit.nextPage();
            var tt = function () {
                $rootScope.WxShare($rootScope.pageTitle(), '优品三悦', location.href, $rootScope.LogoUrl);
            }

            setTimeout(tt, 1000)
            //取消收藏
            $scope.CancelFavorite = function (index, favorite) {
                $http.post("/Product/CancelFavorite", { Id: favorite.Id }).then(function (returnData) {
                    if (returnData.data.isSuccess) {
                        $scope.reddit.items.splice(index, 1);
                    }
                });
            }


        }]);
</script>